/*
-----------------------------------------------------------------------------
This source file is part of DIVA
The project of Engineering Lab, dept. of CSIE, NTNU.

Copyright (c) 2000-2006 The Software Engineering Lab, dept. of CSIE, NTNU.
-----------------------------------------------------------------------------
Filename:    MappingEngine.h
Description: This is the dummy mapping engine for testing.


-----------------------------------------------------------------------------
*/
/*------------------------------------------------------------*/
#ifndef _xVMRelationStruct_H_
#define	_xVMRelationStruct_H_
/*------------------------------------------------------------*/

//#include "vm_wop_entry.h"
//#include "DIVA_VM.h"
//#include "entry/WOP_Entry.h"
#include "vm_wop_pair.h"
#include <deque>
//#include "class_mapping_gui.h"
#include "xMappingNode.h"
#include "ReferenceVM.h"

class xVMRelationStruct {
private:	
	std::vector<xMappingNode *> *_all_mapping_nodes ; 
	static xVMRelationStruct *singleton ;

	xVMRelationStruct() ;
	std::vector<xMappingNode *> xVMRelationStruct::getAllChildren(xMappingNode *current) ;

public:

	static xVMRelationStruct*  getInstance() ;

	/** in a composite structure (mapping tree), return the root node of the mapping tree, without crossing the reference VM */
	std::set<xMappingNode*> VMRS_toCompositeRoot(xMappingNode *current) ;

	DIVA_VM * VMRS_toCompositeRootVM(DIVA_VM *vm);

	///取得目前最新被new出來的VM
	DIVA_VM * VMRS_getNewCreateVM();

	/** return the VM in a vector which contains the next VM that can be walked by a reference VM */
	std::vector<DIVA_VM *> VMRS_nextVMsByRef(DIVA_VM *currentvm,string refName = "") ;
	/**可指定Ref的多個變數名稱,中間請以空白隔開*/
	//vector<DIVA_VM *> VMRS_nextVMsByRefNames(DIVA_VM *currentvm, string refName) ;

	std::map<DIVA_VM *, DIVA_VM *> VMRS_nextVMPairsByRef(DIVA_VM *vm) ;

	/** return the reference VMs which has pointer pointed to the given VM */
	std::vector<DIVA_VM *> VMRS_preVMsByRef(DIVA_VM *vm,string refName = "") ;
	/**可指定Ref的多個變數名稱,中間請以空白隔開*/
	//vector<DIVA_VM *> VMRS_preVMsByRefNames(DIVA_VM *vm, string refName) ;

	//FORLAYOUTTEST
	std::vector<DIVA_VM *> VMRS_getAllVM();
	std::vector<DIVA_VM *> VMRS_getAllVMContainer();
	//if vm has varname , can use this function
	std::vector<DIVA_VM *> VMRS_searchVMByVarname(std::string varname);
	std::vector<DIVA_VM *> VMRS_getSameTypeVM(DIVA_VM* vm);
	bool VMRS_checkSameVMType(DIVA_VM* vm1, DIVA_VM* vm2);


	//

	//取得一個VM的組成VM(composite)
	std::vector<DIVA_VM *> get_subVMs(DIVA_VM *vm);

	std::vector<std::string> get_subVMsVarname(DIVA_VM *vm);
	std::vector<std::string> get_subVMsVarname(std::string str);
	std::vector<std::string> get_subVMsVarname(DIVA_VM *vm, std::string type);
	std::vector<std::string> get_subVMsVarname(std::string str,std::string type);
	///取得同樣type的VM
	std::vector<DIVA_VM *> VMRS_getSameTypeVMs(DIVA_VM*) ;
	//取得這個與VM連結的WOPnode的變數名稱
	string get_wopName(DIVA_VM *vm);
	//取得這個與VM連結VM
	DIVA_VM* get_pointedVM(ReferenceVM *vm);
	//
	bool isPointedNULL(ReferenceVM *vm);
	
};

/*------------------------------------------------------------*/
#endif	//#ifndef _MappingEngine_H_
/*------------------------------------------------------------*/